package com.hotel.project.gateway.apollo;

import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.context.scope.refresh.RefreshScope;
import org.springframework.stereotype.Component;

/**
 * ApolloRefresh  刷新配置
 *
 * @author: peng.ni
 * @date: 2022/04/13
 */
@Slf4j
@Data
@Component
public class ApolloRefreshConfig {
    private final RefreshScope refreshScope;

    public ApolloRefreshConfig(
            final RefreshScope refreshScope) {
        this.refreshScope = refreshScope;
    }

    @ApolloConfigChangeListener(value = ConfigConsts.NAMESPACE_APPLICATION)
    public void onChange(ConfigChangeEvent changeEvent) {
        log.info("before refresh {}", "");
        refreshScope.refresh("");
        log.info("after refresh {}", "");
    }
}
